package com.winchain.provider;

import com.winchain.chainbill.basic.activity.po.BasAct;
import com.winchain.chainbill.basic.activity.service.BasActGrpService;
import com.winchain.chainbill.basic.activity.service.BasActService;
import com.winchain.chainbill.basic.activity.service.BasCusCpnService;
import com.winchain.chainbill.basic.cus.po.CusRec;
import com.winchain.chainbill.basic.cus.service.CusRecService;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CouponSenderProvider {
	@Autowired
	private BasActService basActService;
	@Autowired
	private BasCusCpnService basCusCpnService;
	@Autowired
	private BasActGrpService basActGrpService;
	@Autowired
	private CusRecService cusRecService;

	@RequestMapping({ "/couponSender/send" })
	public void send() {
		String[] states = { "1" };
		List<BasAct> acts = this.basActService.selectByStatesAndGrpIds(states, new String[0]);
		BasAct act;
		String[] grpIds;
		for (Iterator localIterator1 = acts.iterator(); localIterator1.hasNext();) {
			act = (BasAct) localIterator1.next();

			grpIds = this.basActGrpService.selectGrpIdsByActId(act.getActId());
			List<CusRec> cusList = this.cusRecService.selectXfeOrDctCusListByGrpIds(grpIds);
			for (CusRec cus : cusList) {
				this.basCusCpnService.sendCusCpn(cus.getCusId(), act, grpIds);
			}
		}

	}
}
